from import_export import resources
from .models import HostsLists, Assets, HostRes


class HostsResource(resources.ModelResource):
    class Meta:
        model = HostsLists

    def before_import_row(self, row, **kwargs):
        systemname = row.get('systemname')
        ip = row.get('ip')
        (hts, _created) = HostsLists.objects.get_or_create(systemname=systemname,ip=ip)
        row['id']=hts.id


class HostinfoResource(resources.ModelResource):
    class Meta:
        model = HostRes


class AssetsResource(resources.ModelResource):
    class Meta:
        model = Assets
        import_id_fields = ('number',)
